/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package TestCase.Dup;

import classgenerator.logic.Oracle;
import classgenerator.logic.OracleImpl;
import deadCodeRmv.StartMeDCR;
import takatuka.classreader.dataObjs.ClassFile;
import takatuka.classreader.dataObjs.MethodInfo;
import takatuka.classreader.logic.constants.JavaInstructionsOpcodes;
import takatuka.classreader.logic.factory.FactoryFacade;
import takatuka.classreader.logic.factory.FactoryPlaceholder;

/**
 *
 * @author irfan
 */
public class DupTestCase extends StartMeDCR {

    public static void main(String args[]) throws Exception {
        new DupTestCase().start(args);
    }

    @Override
    public void execute(String args[]) throws Exception {
        Oracle oracle = new OracleImpl();
        FactoryFacade factoryFacade = FactoryPlaceholder.getInstanceOf().getFactory();
        ClassFile cFile = oracle.createEmptyClassFile("DupTestCase", "DupTestCase.java");



        MethodInfo constrMethodInfo = oracle.addDefaultConstructor(cFile);
//
//
        int defaultConstrRefInfo = oracle.addMethodRefInCP(cFile, cFile.getThisClass().intValueSigned(),
                oracle.getUTF8FromCP(cFile, constrMethodInfo.getNameIndex().intValueSigned()),
                oracle.getUTF8FromCP(cFile, constrMethodInfo.getDescriptorIndex().intValueSigned()));


        /**
         * added the main method in the class file without any code
         */
        MethodInfo mainMethod = oracle.addMainFunction(cFile);

        /**
         * bipush 100
         */
        oracle.addInstruction(cFile, mainMethod, factoryFacade.createInstruction(JavaInstructionsOpcodes.BIPUSH, factoryFacade.createUn(100).trim(1), mainMethod.getCodeAtt()));



        /**
         * dup
         */
        oracle.addInstruction(cFile, mainMethod, factoryFacade.createInstruction(JavaInstructionsOpcodes.DUP, mainMethod.getCodeAtt()));





        /**s
         * ISTORE_0
         *
         */
        oracle.addInstruction(cFile, mainMethod, factoryFacade.createInstruction(JavaInstructionsOpcodes.ISTORE_0, mainMethod.getCodeAtt()));
        /**
         * ISTORE_1
         *
         */
        oracle.addInstruction(cFile, mainMethod, factoryFacade.createInstruction(JavaInstructionsOpcodes.ISTORE_1, mainMethod.getCodeAtt()));


        /*
         * 
         * printing integer result
         */
        oracle.print(cFile, mainMethod, "Result Should be in sequence of : \n100\n100\nResult is:");
        oracle.print(cFile, mainMethod, 0, true);
        oracle.print(cFile, mainMethod, 1, true);




        /**
         * return
         */
        oracle.addInstruction(cFile, mainMethod, factoryFacade.createInstruction(JavaInstructionsOpcodes.RETURN, mainMethod.getCodeAtt()));
        super.execute(args);
    }
}
